package com.housekeeping.housekeeping.advertisingmanagement.controller.ad;/*
 * @author  pyh
 * @date  2021/1/18 0018 下午 9:48
 * @version 1.0
 * @since JDK1.8_241
 */

import com.alibaba.fastjson.JSONObject;
import com.housekeeping.housekeeping.advertisingmanagement.service.AdMessagesService;
import com.housekeeping.housekeeping.advertisingmanagement.service.impl.AdMessagesServiceImpl;
import com.housekeeping.housekeeping.advertisingmanagement.entity.AdMessages;
import com.housekeeping.housekeeping.advertisingmanagement.utils.ResponseEntitys;
import com.housekeeping.housekeeping.advertisingmanagement.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 添加
 * 1、先获取解析数据
 * 2、将
 * 判断是否获取数据
 */
@WebServlet("/ad/add")
public class AddController extends HttpServlet {
    private AdMessagesService ams =new AdMessagesServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String adMessagesJson = req.getParameter("AdMessages");
        AdMessages adMessages =JSONObject.parseObject(adMessagesJson,AdMessages.class);
        int i = ams.saveAdMessages(adMessages);
        ResponseEntitys<Object> entity = null;
        //判断是否获取数据
        if (i > 0){
            entity = ResponseEntitys.success(null);
        }else {
            entity = ResponseEntitys.error(400005, "添加失败");
        }
        ResponseUtils.resp(resp,entity);
    }
}
